package fun.liuyu2783.txmessage.marketing.mq;

import fun.liuyu2783.txmessage.marketing.dto.Trade;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RocketMQMessageListener(topic = "ORDER_TOPIC_ORDERLY", selectorExpression = "create", consumerGroup = "Goods_Orderly_Confirm_Group", consumeMode = ConsumeMode.ORDERLY)
public class OrderOrderlyConsumer implements RocketMQListener<Trade>, RocketMQPushConsumerLifecycleListener {

    @Override
    public void onMessage(Trade trade) {
        log.info("接收到顺序消息：{}", trade);
    }

    @Override
    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {
        defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    }
}
